package com.example.common;

import com.example.exception.RegisterException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@ControllerAdvice(annotations = {RestController.class, Controller.class})
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R<?> error(Exception e){
        log.info(e.getMessage());
        return R.error(e.getMessage());
    }

    @ExceptionHandler(RegisterException.class)
    @ResponseBody
    public R<?> RegisterException(RegisterException e){
        log.info(e.getMessage());
        return R.error(e.getMessage());
    }


}
